package me.lovetcat.common.util;

import me.lovetcat.common.dto.FieldErrorDto;
import org.springframework.validation.FieldError;

import java.util.ArrayList;
import java.util.List;

/**
 * @author acat on 2017-01-16 10:20
 */
public class WebUtil {

    /**
     * 转换spring校验结果FieldError
     * @param fieldErrors
     * @return
     */
    public static List<FieldErrorDto> setFieldValidErrorMsgs(List<FieldError> fieldErrors){
        List<FieldErrorDto> fieldValidErrorMsgs = new ArrayList<>();
        for(FieldError fieldError : fieldErrors){
            fieldValidErrorMsgs.add(new FieldErrorDto(fieldError.getField(), fieldError.getDefaultMessage()));
        }
        return fieldValidErrorMsgs;
    }

}
